[tox]
minversion=4.5.1
envlist=greet

[testenv]
package = wheel
wheel_build_env = .pkg

[testenv:greet]
skip_install=true
commands=
    python -c "print('\nGreetings, wandb developer!\\nTo execute a tox environment, run `tox run -e <envname>`\n')"

[black]
deps=
    black[jupyter]==23.3.0

[testenv:black{,-check}]
basepython=python3.9
skip_install=true
deps=
    {[black]deps}
commands=
    check: black --check wandb/ tests/ tools/
    !{check}: black {posargs:} wandb/ tests/ tools/

[testenv:mypy{,-report}]
basepython=python3
skip_install=true
deps=
    !{report}: types-click
    !{report}: pandas-stubs
    !{report}: types-Pillow
    !{report}: types-PyYAML
    !{report}: types-Pygments
    !{report}: types-protobuf==4.24.0.4
    !{report}: types-pytz
    !{report}: types-requests
    !{report}: types-setuptools
    !{report}: types-six
    !{report}: types-tqdm
    !{report}: types-openpyxl
    !{report}: mypy
    !{report}: lxml
    !{report}: grpcio
    !{report}: httpx
    report: pycobertura
setenv=
    !{report}: MYPYPATH={toxinidir}
commands=
    !{report}: mypy --install-types --non-interactive --show-error-codes --config-file {toxinidir}/pyproject.toml -p wandb --html-report mypy-results/ --cobertura-xml-report  mypy-results/ --lineprecision-report mypy-results/
    report: pycobertura show --format text mypy-results/cobertura.xml

[testenv:ruff{,-check}]
basepython=python3
skip_install=true
deps=
    ruff
commands=
    check: ruff check {toxinidir}
    !{check}: ruff {posargs:} {toxinidir}

[testenv:auto-codegen{,-check}]
basepython=python3
deps=
    {[black]deps}
commands=
    check: python tools{/}generate-tool.py --check
    !{check}: python tools{/}generate-tool.py --generate {posargs:}

[base]
deps=
    -r{toxinidir}/requirements_test.txt
    -r{toxinidir}/requirements_tools.txt
    !{notebooks}: -r{toxinidir}/requirements_dev.txt
    notebooks: nbclient
    notebooks: nbconvert
    notebooks: nbformat
    notebooks: ipykernel
    notebooks: ipython<8.17.1
setenv=
    ; Setting low network buffer so that we exercise flow control logic
    WANDB__NETWORK_BUFFER=1000
    COVERAGE_FILE={envdir}/.coverage
    YEA_WANDB_VERSION=0.9.20
passenv=
    USERNAME
    CI_PYTEST_SPLIT_ARGS

[testenv:{,core-}{,notebooks-,importer-wandb-,importer-mlflow-}py{37,38,39,310,311,312}]
install_command=
    ; pytorch installations on non-darwin need the `-f`
    pip install --timeout 600 --extra-index-url https://download.pytorch.org/whl/cpu {opts} {packages}
deps=
    {[base]deps}
    !py37-!mlflow: .[reports]
    !py37-!mlflow: polyfactory
    wheel
    build
    nox
    importer-mlflow: pydantic<2
    importer-wandb: pydantic>=2
    importer: polars
    importer: rich
    importer: filelock
setenv=
    {[base]setenv}
    WINDIR=C:\\Windows
    GOCOVERDIR={tox_root}/.coverage
    WANDB_ERROR_REPORTING=false
passenv=
    {[base]passenv}
    CI_PYTEST_PARALLEL
    CI
    importer-wandb: WANDB_TEST_SERVER_URL2
allowlist_externals=
    mkdir
    nox
    go
    ./wini
commands_pre=
    notebooks: ipython kernel install --user --name=wandb_python
    mkdir -p test-results .coverage
    core: ./wini package wandb-core --coverage --install
commands=
    pytest {env:CI_PYTEST_SPLIT_ARGS:} -n=8 --durations=20 --junitxml=test-results/junit.xml --cov --cov-report=xml --no-cov-on-fail --timeout 300 {posargs}
commands_post=
    core: go tool covdata textfmt -i=.coverage -o coverage.txt


[testenv:launch-release]
deps=
    pytest
    wandb
    wandb[launch]
commands=
    wandb login
    pytest tests/release_tests/test_launch/ {posargs}

[testenv:func-{,core-}{base-,mitm-,docs-}py{37,38,39,310,311,312}]
install_command=pip install --extra-index-url https://download.pytorch.org/whl/cpu {opts} {packages}
deps =
    yea-wandb=={env:YEA_WANDB_VERSION}
    core: wheel
    core: build
    core: nox
    core: rich
setenv=
    {[base]setenv}
    YEACOV_SOURCE={envsitepackagesdir}/wandb/
    core: GOCOVERDIR={tox_root}/.go-coverage
    WANDB_ERROR_REPORTING=false
passenv=
    {[base]passenv}
    SHARD
    WANDB_API_KEY
    core: GOCOVERDIR
allowlist_externals=
    mkdir
    core: nox
    core: go
    core: ./wini
commands_pre=
    mkdir -p test-results
    core: mkdir -p {env:GOCOVERDIR}
    core: ./wini package wandb-core --coverage --install
commands=
    base: yea {env:CI_PYTEST_SPLIT_ARGS:} --strict --shard {env:SHARD:default} --mitm run {posargs:--all}
    mitm: yea {env:CI_PYTEST_SPLIT_ARGS:} --strict --shard mitm --mitm run {posargs:tests/standalone_tests}
    docs: yea {env:CI_PYTEST_SPLIT_ARGS:} --strict --shard docs --mitm --yeadoc run {posargs:tests/functional_tests}
commands_post=
    core: go tool covdata textfmt -i={env:GOCOVERDIR} -o coverage.txt


[testenv:func-{llm,kfp}-py{37,38,39,310,311,312}]
install_command=pip install --extra-index-url https://download.pytorch.org/whl/cpu {opts} {packages}
deps=
    yea-wandb=={env:YEA_WANDB_VERSION}
setenv=
    {[base]setenv}
    YEACOV_SOURCE={envsitepackagesdir}/wandb/
    kfp: WB_PROBE_PACKAGE=true
    WANDB_ERROR_REPORTING=false
passenv=
    {[base]passenv}
;    llm: WANDB_API_KEY
    llm: OPENAI_API_KEY
    llm: CO_API_KEY
allowlist_externals=
    mkdir
commands_pre=
    mkdir -p test-results
;    llm: wandb login --relogin {env:WANDB_API_KEY}
commands=
;    llm: yea {env:CI_PYTEST_SPLIT_ARGS:} --strict -p wandb:mockserver-relay=true -p wandb:mockserver-relay-remote-base-url=https://api.wandb.ai --shard llm run {posargs:--all}
    llm: yea {env:CI_PYTEST_SPLIT_ARGS:} --strict --shard llm run {posargs:--all}
    kfp: yea {env:CI_PYTEST_SPLIT_ARGS:} --strict -p wandb:mockserver-bind=0.0.0.0 -p wandb:mockserver-host=__auto__ --shard kfp run {posargs:--all}

[testenv:standalone-{local,cpu,gpu,tpu}-py{37,38,39,310,311,312}]
install_command=pip install --extra-index-url https://download.pytorch.org/whl/cpu {opts} {packages}
setenv=
    {[base]setenv}
    YEACOV_SOURCE={envsitepackagesdir}/wandb/
    WANDB_PROJECT=standalone-{env:DATE}
    WANDB_ERROR_REPORTING=false
passenv=
    DATE
    USERNAME
    WANDB_API_KEY
    SHARD
deps=
    yea-wandb=={env:YEA_WANDB_VERSION}
    wheel
    build
    nox
    rich
allowlist_externals=
    mkdir
    nox
    go
    ./wini
commands_pre=
    wandb login --relogin {env:WANDB_API_KEY}
    ./wini package wandb-core --coverage --install
commands=
    mkdir -p test-results
    !{local}: yea --debug --strict -p wandb:mockserver-relay=true -p wandb:mockserver-relay-remote-base-url=https://api.wandb.ai --shard standalone-{env:SHARD:cpu} run {posargs:--all}
    local: yea --debug --strict -p wandb:mockserver-bind=0.0.0.0 -p wandb:mockserver-host=__auto__ -p wandb:mockserver-relay=true -p wandb:mockserver-relay-remote-base-url=http://localhost:5000 --shard standalone-cpu run {posargs:--all}

[testenv:regression-{yolov5,huggingface,keras,tensorflow,pytorch,wandb-sdk-standalone,wandb-sdk-examples,wandb-sdk-other,s3,sagemaker}-py{37,38,39,310,311,312}]
install_command=pip install --extra-index-url https://download.pytorch.org/whl/cpu {opts} {packages}
deps=
    pyyaml
    six
    wandb
    shortuuid
setenv=
    {[base]setenv}
    WANDB_ERROR_REPORTING=false
passenv=*
allowlist_externals=
    git
    rm
    env
changedir=
    {envdir}
commands_pre=
    rm -rf wandb-testing
    git clone https://github.com/wandb/wandb-testing.git
commands=
    yolov5: env bash -c "./wandb-testing/regression/do-cloud-regression.sh tests/main/yolov5/ {posargs}"
    huggingface: env bash -c "./wandb-testing/regression/do-cloud-regression.sh tests/main/huggingface/ {posargs}"
    keras: env bash -c "./wandb-testing/regression/do-cloud-regression.sh tests/main/keras/ {posargs}"
    tensorflow: env bash -c "./wandb-testing/regression/do-cloud-regression.sh tests/main/tensorflow/ {posargs}"
    pytorch: env bash -c "./wandb-testing/regression/do-cloud-regression.sh tests/main/pytorch/ {posargs}"
    wandb-sdk-standalone: env bash -c "./wandb-testing/regression/do-cloud-regression.sh tests/main/wandb-git/client/standalone_tests/ {posargs}"
    wandb-sdk-examples: env bash -c "./wandb-testing/regression/do-cloud-regression.sh tests/main/wandb-git/examples/ {posargs}"
    wandb-sdk-other: env bash -c "./wandb-testing/regression/do-cloud-regression.sh tests/main/wandb-git/wandb-examples/ {posargs}"
    sagemaker: env bash -c "./wandb-testing/regression/do-sagemaker-regression.sh tests/sagemaker-beta/ {posargs}"
    s3: env bash -c "./wandb-testing/regression/do-s3-regression.sh tests/s3-beta/ {posargs}"

[testenv:executor-{pex,uwsgi,gunicorn}]
install_command=pip install --extra-index-url https://download.pytorch.org/whl/cpu {opts} {packages}
basepython=python3.9
deps=
    {uwsgi,gunicorn}: flask
    gunicorn: gunicorn
    uwsgi: uwsgi
    pex: pex
setenv=
    {[base]setenv}
    WANDB_ERROR_REPORTING=false
passenv=*
allowlist_externals=
    bash
commands=
    bash tests/standalone_tests/executor_tests/{envname}.sh {posargs}

[testenv:cover{,-func}-{linux,mac,win}{,-circle}]
skip_install=true
basepython=python3
deps=
    coverage[toml]
setenv=
    circle: CIRCLE_BUILD_NUM={env:CIRCLE_WORKFLOW_ID}
passenv=
    circle: CI
    circle: CIRCLECI
    circle: CIRCLE_*
    circle: CODECOV_*
    COVERAGE_DIR
allowlist_externals=
    mkdir
    cp
    !{win}: env
commands=
    mkdir -p cover-results
    !{win}: env bash -c '{envpython} -m coverage combine {toxworkdir}/{env:COVERAGE_DIR}/.coverage*'
    !{win}: env bash -c '{envpython} -m coverage xml --ignore-errors'
    win: {envpython} -m coverage combine '{toxworkdir}\\{env:COVERAGE_DIR}\\.coverage'
    win: {envpython} -m coverage xml --ignore-errors

    cp .coverage coverage.xml cover-results/
    !{win}: coverage report --rcfile=.coveragerc
    win: {envpython} -m coverage report --rcfile=.coveragerc

[testenv:pod-store]
allowlist_externals=
    mkdir
    cp
commands=
    mkdir -p /wandb-store/test-results
    cp -rp test-results /wandb-store/test-results

[testenv:bumpversion]
basepython=python3
skip_install=true
deps=
    bump2version
commands=
    python ./tools/bumpversion-tool.py {posargs:--to-dev }
